<?php

namespace app\api\controller;



use app\common\controller\Api;

/**
 * 开放小区
 */
class Community extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    //小区列表
    public function lists()
    {
        $longitude = input('lng','');
        $latitude = input('lat','');
        $list = \app\admin\model\Community::order('weigh desc')->select();
        foreach ($list as $k => $item) {
            if ($item[ 'lng' ] && $item[ 'lat' ]) {
                $distance = getDistance((float) $item[ 'lng' ], (float) $item[ 'lat' ], (float) $longitude, (float) $latitude);
                $list[ $k ][ 'distance' ] = $distance;
            } else {
                $list[ $k ][ 'distance' ] = 0;
            }

        }

        //$list = $list->toArray();

        array_multisort(array_column($list, 'distance'), SORT_ASC, $list);
        $this->success('',$list);
    }
}